var sliderWidth = 125; // 需要设置slider的宽度，用于计算中间位置
const app = getApp();

Page({
    data: {
        imgUrl: app.globalData.APIURL +'/img',
        orderList: [],
        pageNumber: 1,
        currentPageNum: 1,
        isEmpty: '',
    },
    onLoad: function () {
        var that = this;
        wx.setNavigationBarTitle({
            title: '订单管理'
        })

        this.getOrderList();
    },
    // onReady:function(){
    //     this.onPullDownRefresh();
    // },

    onPullDownRefresh: function () {
        this.setData({
            currentPageNum: 1
        })
        this.getOrderList(1);
    },
    onReachBottom: function () {

        //上拉加载更多
        if (this.data.isEmpty != 'nomore') {
            var pageNum = this.data.currentPageNum + 1;
            this.setData({
                currentPageNum: pageNum
            })
            this.getOrderList(pageNum);
        }
    },
    getOrderList: function (pageNum = 1) {
        wx.showLoading({
            title: '加载中',
        });
        var that = this;
        wx.request({
            url: app.globalData.APIURL + '/vending-admin/homepage/getOrderList',
            data: {
                token: app.globalData.token,
                pageNumber: pageNum,
                type: 99
            },
            // method:'GET',
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {
                // 停止刷新
                wx.stopPullDownRefresh();
                wx.hideLoading();
                console.log(res.data)
                if (app.requestEro(res.data.success, res.data.msg)) {
                    if (res.data.pages.list.length < 1 && res.data.pages.firstPage) {
                        that.setData({
                            isEmpty: 'blank',
                        })
                        console.log(that.data.isEmpty)
                    }else if (res.data.pages.list.length < 1 && !res.data.pages.firstPage) {
                        that.setData({
                            isEmpty: 'nomore',
                        })
                        console.log(that.data.isEmpty)
                    } else {
                        var list = that.data.orderList;
                        var showList = res.data.pages.firstPage ? res.data.pages.list : list.concat(res.data.pages.list)
                        that.setData({
                            orderList: showList,
                            currentPageNum: res.data.pages.pageNumber
                        })
                    }
                }

            },
            fail: function (err) {
                console.log(err);
                wx.hideLoading();
            }
        })

    }


});